package { 
	import flash.geom.Point;
	import flash.net.SharedObject;
	import flash.utils.Dictionary;
	
	import org.flixel.*;
	
	
	public class CreditState extends FlxState {

		
		public function CreditState() {
			super();
			//this.add(new FlxSprite(0,0, Res.credits));
			var blackbg:FlxSprite = new FlxSprite();
			blackbg.makeGraphic(FlxG.width, FlxG.height, 0x000000);
			blackbg.drawRect(0, 0, FlxG.width, FlxG.height, 0x000000);
			
			var credits:String = 
				"PROGRAMMING\n" +
				"Dustin, Chanel, Mai, Ryan\n\n" +
				"ART\n" +
				"Ryan, Mai, Marianne\n\n" +
				"MUSIC AND SOUND EFFECTS\n" +
				"Chanel, rengoku-teien.com, and the Freesound Project contributers (Robinhood76, thanvannispen, gyzhor, vair01, joe93barlow, sandyrb, Sergenious, nthompson)\n\n" +
				"VIDEO\n" +
				"Ian Hubert\n\n" +
				"SPECIAL THANKS\n" +
				"To everyone who supported us at the University of Washington";
			
			var creditText:FlxText = new FlxText(50,0, FlxG.width - 100, credits, false);
			creditText.setFormat("Courier New", 20, 0xFFFFFF, "left");
			creditText.y = (FlxG.height - creditText.height) / 2;
			
			add(blackbg);
			add(creditText);
		}
		
		public override function update():void {
			if (FlxG.mouse.justPressed()) {
				FlxG.switchState(new MenuState());
			}
		}
//
//		protected var music:Class = GameState.forest;
//		
//		[Embed(source="../assets/returnToMain.png")] protected var returnImg:Class;
//		
//		//Cookie
//		protected var localInformation:SharedObject;
//		
//		//Music and Mute Button.
//		protected var playIt:Boolean;
//		protected var musicIco:FlxSprite;
//		
//		// Game sizing constants
//		public static const CELL_SIZE:int = 46;
//		public static const ROWS:int = 11;
//		public static const COLS:int = 11;
//		public static const X_OFFSET:int = 5;
//		public static const Y_OFFSET:int = 5;
//		
//		// includes the bounding bars that contribute to the offset.
//		public static const GRID_WIDTH:int = (CELL_SIZE * COLS) + (2 * X_OFFSET);
//		public static const GRID_HEIGHT:int = (CELL_SIZE * ROWS) + (2 * Y_OFFSET);
//		
//		protected var theOverlay:FlxSprite;
//		
//		// Index -> item, row major order for indices
//		protected var tileMap:Dictionary;
//		protected var Ground:FlxGroup;
//		protected var Blocks:FlxGroup;
//		protected var Tiles:FlxGroup;
//		protected var returnButton:FlxSprite;
//		protected var bin:ArrowBin;
//		
//		protected var player:Player = null;
//		protected var playerImageSprite:FlxSprite = null;
//
//		protected var train:Train = null;
//		protected var collideTrain:FlxGroup = null;
//		
//		protected var NPCGroup:FlxGroup;
//		protected var door:FlxSprite;
//
//		protected var playerLastX:int;
//		protected var playerLastY:int;
//		
//		
//		//Text Control Variables
//		protected var OpeningText:Array = new Array("Move with WASD, interact with NPCs by walking up to them. Head back to the main menu " +
//			"anytime by hitting the Return to Main Menu Button.");
//		protected var starting:Boolean;
//		protected var oCount:int = 0;
//		protected var EndingText:Array = new Array();
//		protected var ending:Boolean;
//		protected var eCount:int = 0;
//		protected var StoryText:FlxText;
//		protected var StoryNPC:NPC;
//		
//		protected var NPCMessageUp:Boolean = false;
//		protected var MessageCounter:int = 10;
//
//		
//		public function CreditState() {
//			this.add(new FlxSprite(0,0,GameState.bg));
//			
//			//Initiate music and player options to turn it off.
//			localInformation = SharedObject.getLocal("elementalGameInfo");
//			
//			var status:String = localInformation.data["music"];
//			if (status != null) {
//				if (status != "mute") {
//					musicIco = new FlxSprite(676, 0, GameState.nm);
//					Elemental.MUTE = false;
//					playIt = true;
//				} else {
//					musicIco = new FlxSprite(676, 0, GameState.m);
//					Elemental.MUTE = true;
//				}
//			} else {
//				localInformation.data["music"] = "play";
//				localInformation.flush();
//				musicIco = new FlxSprite(676, 0, GameState.nm);
//				Elemental.MUTE = false;
//				playIt = true;
//			}
//			this.add(musicIco);
//			
//			returnButton = new FlxSprite(700-92, 0, returnImg);
//			var trainString:Array = new Array("1","1","1","1","1");
//			var ArrowArray:Array = new Array(1,1,1,1);
//			var theNPCs:Array = new Array();
//			
//			var TBox:FlxText = new FlxText(510, 200, 190, "HINT BOX", false);
//			TBox.setFormat("helvetica", 20, 0x000000, "center", 0x662222);
//			this.add(TBox);
//			var TutorialText:Array = new Array("Head back to the Menu by hitting the Return to Main Menu Button in the top " +
//				"right corner.");
//			if (TutorialText.length > 0) {
//				var TTextOne:FlxText = new FlxText(520, 230, 180, TutorialText[0], false);
//				TTextOne.setFormat("helvetica", 16, 0x000000, "left", 0x662222);
//				this.add(TTextOne);
//				if (TutorialText.length > 1) {
//					var TTextTwo:FlxText = new FlxText(520, 330, 180, TutorialText[1], false);
//					TTextTwo.setFormat("helvetica", 16, 0xf000000, "left", 0x662222);
//					this.add(TTextTwo);
//					if (TutorialText.length > 2) {
//						var TTextThree:FlxText = new FlxText(520, 430, 180, TutorialText[2], false);
//						TTextThree.setFormat("helvetica", 16, 0x000000, "left", 0x662222);
//						this.add(TTextThree);
//					}
//				}
//			}
//			StoryText = new FlxText(50, 520, 460, "", false);
//			StoryText.setFormat("helvetica", 15, 0x000000, "center", 0x662222);
//			StoryText.text = OpeningText[oCount];
//			theOverlay = new FlxSprite(0,0,GameState.overlay);
//			this.add(theOverlay);
//			this.add(StoryText);
//			
//			tileMap = new Dictionary();
//			
//			//Initialize Flx Groups
//			Ground = new FlxGroup();
//			
//			collideTrain = new FlxGroup();
//			Blocks = new FlxGroup();
//
//			NPCGroup = new FlxGroup();
//
//			
//			var tBound:FlxTileblock = new FlxTileblock(0, 0, GRID_WIDTH, Y_OFFSET);
//			var bBound:FlxTileblock = new FlxTileblock(0, GRID_HEIGHT - Y_OFFSET, GRID_WIDTH, Y_OFFSET);
//			var lBound:FlxTileblock = new FlxTileblock(0, 0, X_OFFSET, GRID_HEIGHT);
//			var rBound:FlxTileblock = new FlxTileblock(GRID_WIDTH - X_OFFSET, 0, X_OFFSET, GRID_HEIGHT);
//			tBound.loadTiles(GameState.topBoundImage, GRID_WIDTH,Y_OFFSET, 0);
//			bBound.loadTiles(GameState.bottomBoundImage, GRID_WIDTH,Y_OFFSET, 0);
//			lBound.loadTiles(GameState.leftBoundImage, X_OFFSET, GRID_HEIGHT, 0);
//			rBound.loadTiles(GameState.rightBoundImage, X_OFFSET, GRID_HEIGHT, 0);
//			Blocks.add(tBound);
//			Blocks.add(lBound);
//			Blocks.add(rBound);
//			Blocks.add(bBound);
//			
//			//Parse and create map
//			for (var i:int = 0; i < ROWS; i++) {
//				for (var j:int = 0; j < COLS; j++) {
//					var index:int = (i*COLS) + j;
//					var pos:Point = getPointFromIndex(index);
//					var g:FlxTileblock;
//					g = new FlxTileblock(pos.x, pos.y, CELL_SIZE, CELL_SIZE);
//					g.loadTiles(GameState.grassTiles, CELL_SIZE, CELL_SIZE, 0);
//
//					Ground.add(g);
//					
//				}
//			}
//			//player
//			playerImageSprite = new FlxSprite(j*CELL_SIZE + X_OFFSET, i*CELL_SIZE + Y_OFFSET, null);
//			player = new Player(0*CELL_SIZE + X_OFFSET, 0*CELL_SIZE + Y_OFFSET, playerImageSprite);
//			
//			//Construct the Train
//			train = new Train(player);
//			for (var k:int = 0; k < trainString.length; k++) {
//				if (trainString[k] == "1") {
//					var chicken:Chicken = new Chicken(player.x, player.y, null);
//					train.addAnimal(chicken);
//					collideTrain.add(chicken);
//				} else if (trainString[k] == "2") {
//					var goat:Goat = new Goat(player.x, player.y, null);
//					train.addAnimal(goat);
//					collideTrain.add(goat);
//				}
//			}
//			
//			var a:NPC = new NPC(0,100, "maskedPoof", "Welcome to the Credits Map, Talk to other Poofs to see those responsible" +
//				"for the games content.", "");
//			NPCGroup.add(a);
//			
//			var b:NPC = new NPC(281,281,"magnifico", "This game was created by Dustin Abramson, Mai Dang, Chanel Huang, "
//				+ "and Ryan Sherritt.","");
//			NPCGroup.add(b);
//			var c:NPC = new NPC(143,373,"resistanceLeader","Sound effects from the freesound project."
//				+ "  By: Robinhood76, thanvannispen, gyzhor, uair01, joe93barlow, sandyrb, Sergenious, nthompson, "
//				+ " and Chanel","");
//			NPCGroup.add(c);
//			
//			var d:NPC = new NPC(373,373,"oldWastePoofMale","Background thanks to 煉獄庭園"
//				+ "at rengoku-teien.com, Menu Music by Dustin Abramson.","");
//			NPCGroup.add(d);
//			
//			var e:NPC = new NPC(400,100,"oldWastePoofFemale","This game was made for the University of Washington" +
//				" Games Capstone with the esteemed advice of professors, teaching assistants, and all the wonderful play testers.","");
//			NPCGroup.add(e);
//			
//			var f:NPC = new NPC(100,100,"poofFemale","Opening Video created by the talented and handsome Ian Hubert.","");
//			NPCGroup.add(f);
//			
//			var another:NPC = new NPC(450,450,"poofMale","Menu Art and Eaten by a Monster Art created by Marianne Lee","");
//			NPCGroup.add(another);
//			
//			var h:NPC = new NPC(50,400,"farmer","Poof, Elemental, and Final Boss Art by Mai Dang. Most other art and animations created by " +
//				"Ryan Sherritt. So many we were too lazy to name them all.","");
//			NPCGroup.add(h);
//			
//			this.add(Ground);
//			this.add(Blocks);
//			this.add(Tiles);
//			
//			
//			
//			this.add(collideTrain);
//			this.add(NPCGroup);
//			this.add(player);
//			this.add(playerImageSprite);
//			this.add(returnButton);
//			//beams and arrows
//			bin = new ArrowBin((CELL_SIZE * COLS) + (2 * X_OFFSET), 0, 4, 1, ArrowArray);
//			this.add(bin);
//			
//			
//			
//			//door
//			var posdr:Point = getPointFromIndex(6);
//			
//			
//			
//		}
//		
//		public override function update():void {
//			super.update();
//			train.updateTrain();
//			
//				if (playIt && !Elemental.MUTE && FlxG.music != null && !FlxG.music.active) {
//					playIt = false;
//					FlxG.playMusic(music);
//				}
//				
//				//Updates whether the game is muted or not.
//				if (FlxG.mouse.justPressed() && musicIco.overlapsPoint(FlxG.mouse.screenX, FlxG.mouse.screenY)) {
//					if (Elemental.MUTE) {
//						FlxG.playMusic(music);
//						localInformation.data["music"] = "play";
//						localInformation.flush();
//						musicIco.loadGraphic(GameState.nm);
//						Elemental.MUTE = false;
//					} else {
//						if (FlxG.music != null && FlxG.music.active) {
//							FlxG.music.stop();
//						}
//						localInformation.data["music"] = "mute";
//						localInformation.flush();
//						musicIco.loadGraphic(GameState.m);
//						Elemental.MUTE = true;
//					}
//				}
//				
//				FlxG.overlap(NPCGroup, player, displayMessage);
//				FlxG.collide(Blocks, player);
//				FlxG.collide(Blocks, collideTrain, returnAnimal);
//				
//				if (NPCMessageUp) {
//					if (MessageCounter < 0) {
//						NPCMessageUp = false;
//						StoryText.text = "";
//					} else {
//						MessageCounter--;
//					}
//				}
//			
//			playerLastX = player.x;
//			playerLastY = player.y;
//			if (FlxG.mouse.justPressed() && returnButton.overlapsPoint(FlxG.mouse.screenX, FlxG.mouse.screenY)) {
//				FlxG.switchState(new MenuState());
//			}
//		}
//		/**
//		 * Returns upper left point of cell index.
//		 */
//		public static function getPointFromIndex(index:int):Point {
//			var row:int = index / COLS;
//			var col:int = index - (row * COLS); 
//			return new Point(col * CELL_SIZE + X_OFFSET, row * CELL_SIZE + Y_OFFSET);
//		}
//		
//		/**
//		 * If the end game winning conditions are met (if the player gets the chest).
//		 **/
//		private function exit(obj1:FlxObject, obj2:FlxObject):void {
//			FlxG.switchState(new MenuState()); 
//		}
//		
//		/**
//		 * The collision function for animals and walls. If the animal hits a wall
//		 * it is set on a path to return to the train. If it collides a second
//		 * time while returning it simply is teleported back to the train.
//		 * 
//		 * Not the greatest, but functional for now. 
//		 **/
//		private function returnAnimal(obj1:FlxObject, animal:TrainAnimal):void {
//			if (animal.returning && animal.collisions == 0) {
//				animal.collisions = 4;
//				animal.returning = false;
//				animal.thrown = false;
//			} else {
//				animal.returning = true;
//				Math.max(animal.collisions--, 0);
//				animal.stopThrowingAnim();
//			}
//		}
//		
//		private function displayMessage(theNPC:NPC, player:Player):void {
//			MessageCounter = 10;
//			NPCMessageUp = true;
//			StoryText.text = theNPC.message;
//		}
	}
}
